package com.amit;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(name="B",urlPatterns={"/b.jlc"},loadOnStartup=1)
public class ServletB extends HttpServlet {
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		
		System.out.println("ServletB-init()");
		
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		System.out.println("ServletB-dopost");
		String nm=request.getParameter("fname");
		String em=request.getParameter("email");
		String ip=request.getRemoteAddr();
		
		String msg="<h1>Hello"+nm+"<br>YOUR email is"+em;
		msg=msg+"<br> your ip is"+ip;
		request.setAttribute("MSG", msg);
		RequestDispatcher rd=request.getRequestDispatcher("c.jlc");
		rd.forward(request, response);
		 
	}
	
	@Override
	public void destroy() {
		
		System.out.println("ServletB-destroy()");
	}
	
}
